package com.lmr.service;

import com.lmr.module.InMessage;
import com.lmr.module.OutMessage;
import com.lmr.utils.SystemInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

/**
 * Created by ldd on 2019/12/31.
 */
@Service
public class WebSocketService {

    //注入消息模板
    @Autowired
    private SimpMessagingTemplate messagingTemplate;


    //推送SystemInfo
    public void onPushSystemInfo(){
        messagingTemplate.convertAndSend( "/topic/SystemInfo", SystemInfo.revertSystem() );
    }



    //单聊
    public void onChatUserMessage(InMessage inMessage){
        OutMessage outMessage = new OutMessage(  );
        outMessage.setContent( inMessage.getContent() );
        outMessage.setFromName( inMessage.getFromName() );
        messagingTemplate.convertAndSend( "/chat/"+inMessage.getToName(), outMessage);
    }

}
